home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / drivers / scsi / NCR5380.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  10.1 KB  |  331 lines

  1. /* 
  2.  * NCR 5380 defines
  3.  *
  4.  * Copyright 1993, Drew Eckhardt
  5.  *    Visionary Computing
  6.  *    (Unix consulting and custom programming)
  7.  *     drew@colorado.edu
  8.  *      +1 (303) 666-5836
  9.  *
  10.  * DISTRIBUTION RELEASE 4
  11.  *
  12.  * For more information, please consult 
  13.  *
  14.  * NCR 5380 Family
  15.  * SCSI Protocol Controller
  16.  * Databook
  17.  * NCR Microelectronics
  18.  * 1635 Aeroplaza Drive
  19.  * Colorado Springs, CO 80916
  20.  * 1+ (719) 578-3400
  21.  * 1+ (800) 334-5454
  22.  */
  23.  
  24. /*
  25.  * $Log: NCR5380.h,v $
  26.  * Revision 1.3  1994/01/19  05:24:40  drew
  27.  * Added support for TCR LAST_BYTE_SENT bit.
  28.  *
  29.  * Revision 1.3  1994/01/19  05:24:40  drew
  30.  * Added support for TCR LAST_BYTE_SENT bit.
  31.  *
  32.  * Revision 1.2  1994/01/15  06:14:11  drew
  33.  * REAL DMA support, bug fixes.
  34.  *
  35.  * Revision 1.1  1994/01/15  06:00:54  drew
  36.  * Initial revision
  37.  */
  38.  
  39. #ifndef NCR5380_H
  40. #define NCR5380_H
  41.  
  42. #define NCR5380_PUBLIC_RELEASE 4
  43.  
  44. #define NDEBUG_ARBITRATION    0x1
  45. #define NDEBUG_AUTOSENSE    0x2
  46. #define NDEBUG_DMA        0x4
  47. #define NDEBUG_HANDSHAKE    0x8
  48. #define NDEBUG_INFORMATION    0x10
  49. #define NDEBUG_INIT        0x20
  50. #define NDEBUG_INTR        0x40
  51. #define NDEBUG_LINKED        0x80
  52. #define NDEBUG_MAIN        0x100
  53. #define NDEBUG_NO_DATAOUT    0x200
  54. #define NDEBUG_NO_WRITE        0x400
  55. #define NDEBUG_PIO        0x800
  56. #define NDEBUG_PSEUDO_DMA    0x1000
  57. #define NDEBUG_QUEUES        0x2000
  58. #define NDEBUG_RESELECTION    0x4000
  59. #define NDEBUG_SELECTION    0x8000
  60. #define NDEBUG_USLEEP        0x10000
  61. #define NDEBUG_LAST_BYTE_SENT    0x20000
  62. #define NDEBUG_ABORT        0x40000
  63. #define NDEBUG_MERGING        0x80000
  64.  
  65. /* 
  66.  * The contents of the OUTPUT DATA register are asserted on the bus when
  67.  * either arbitration is occuring or the phase-indicating signals (
  68.  * IO, CD, MSG) in the TARGET COMMAND register and the ASSERT DATA
  69.  * bit in the INTITIATOR COMMAND register is set.
  70.  */
  71.  
  72. #define OUTPUT_DATA_REG         0       /* wo DATA lines on SCSI bus */
  73. #define CURRENT_SCSI_DATA_REG   0       /* ro same */
  74.  
  75. #define INITIATOR_COMMAND_REG    1    /* rw */
  76. #define ICR_ASSERT_RST        0x80    /* rw Set to assert RST  */
  77. #define ICR_ARBITRATION_PROGRESS 0x40    /* ro Indicates arbitration complete */
  78. #define ICR_TRI_STATE        0x40    /* wo Set to tri-state drivers */
  79. #define ICR_ARBITRATION_LOST    0x20    /* ro Indicates arbitration lost */
  80. #define ICR_DIFF_ENABLE        0x20    /* wo Set to enable diff. drivers */
  81. #define ICR_ASSERT_ACK        0x10    /* rw ini Set to assert ACK */
  82. #define ICR_ASSERT_BSY        0x08    /* rw Set to assert BSY */
  83. #define ICR_ASSERT_SEL         0x04    /* rw Set to assert SEL */
  84. #define ICR_ASSERT_ATN        0x02    /* rw Set to assert ATN */
  85. #define ICR_ASSERT_DATA        0x01    /* rw SCSI_DATA_REG is asserted */
  86.  
  87. #ifdef DIFFERENTIAL
  88. #define ICR_BASE        ICR_DIFF_ENABLE
  89. #else
  90. #define ICR_BASE        0
  91. #endif
  92.  
  93. #define MODE_REG        2
  94. /*
  95.  * Note : BLOCK_DMA code will keep DRQ asserted for the duration of the 
  96.  * transfer, causing the chip to hog the bus.  You probably don't want 
  97.  * this.
  98.  */
  99. #define MR_BLOCK_DMA_MODE    0x80    /* rw block mode DMA */
  100. #define MR_TARGET        0x40    /* rw target mode */
  101. #define MR_ENABLE_PAR_CHECK   0x20    /* rw enable parity checking */
  102. #define MR_ENABLE_PAR_INTR    0x10    /* rw enable bad parity interrupt */
  103. #define MR_ENABLE_EOP_INTR    0x08    /* rw enabble eop interrupt */
  104. #define MR_MONITOR_BSY    0x04    /* rw enable int on unexpected bsy fail */
  105. #define MR_DMA_MODE        0x02    /* rw DMA / pseudo DMA mode */
  106. #define MR_ARBITRATE        0x01    /* rw start arbitration */
  107.  
  108. #ifdef PARITY
  109. #define MR_BASE            MR_ENABLE_PAR_CHECK
  110. #else
  111. #define MR_BASE            0
  112. #endif
  113.  
  114. #define TARGET_COMMAND_REG    3
  115. #define TCR_LAST_BYTE_SENT    0x80    /* ro DMA done */
  116. #define TCR_ASSERT_REQ        0x08    /* tgt rw assert REQ */
  117. #define TCR_ASSERT_MSG        0x04    /* tgt rw assert MSG */
  118. #define TCR_ASSERT_CD        0x02    /* tgt rw assert CD */
  119. #define TCR_ASSERT_IO        0x01    /* tgt rw assert IO */
  120.  
  121. #define STATUS_REG        4    /* ro */
  122. /*
  123.  * Note : a set bit indicates an active signal, driven by us or another 
  124.  * device.
  125.  */
  126. #define SR_RST            0x80    
  127. #define SR_BSY            0x40
  128. #define SR_REQ            0x20
  129. #define SR_MSG            0x10
  130. #define SR_CD            0x08
  131. #define SR_IO            0x04
  132. #define SR_SEL            0x02
  133. #define SR_DBP            0x01
  134.  
  135. /*
  136.  * Setting a bit in this register will cause an interrupt to be generated when 
  137.  * BSY is false and SEL true and this bit is asserted  on the bus.
  138.  */
  139. #define SELECT_ENABLE_REG    4    /* wo */
  140.  
  141. #define BUS_AND_STATUS_REG    5    /* ro */
  142. #define BASR_END_DMA_TRANSFER    0x80    /* ro set on end of transfer */
  143. #define BASR_DRQ        0x40    /* ro mirror of DRQ pin */
  144. #define BASR_PARITY_ERROR    0x20    /* ro parity error detected */
  145. #define BASR_IRQ        0x10    /* ro mirror of IRQ pin */
  146. #define BASR_PHASE_MATCH    0x08    /* ro Set when MSG CD IO match TCR */
  147. #define BASR_BUSY_ERROR        0x04    /* ro Unexpected change to inactive state */
  148. #define BASR_ATN         0x02    /* ro BUS status */
  149. #define BASR_ACK        0x01    /* ro BUS status */
  150.  
  151. /* Write any value to this register to start a DMA send */
  152. #define START_DMA_SEND_REG    5    /* wo */
  153.  
  154. /* 
  155.  * Used in DMA transfer mode, data is latched from the SCSI bus on
  156.  * the falling edge of REQ (ini) or ACK (tgt)
  157.  */
  158. #define INPUT_DATA_REG            6    /* ro */
  159.  
  160. /* Write any value to this register to start a DMA recieve */
  161. #define START_DMA_TARGET_RECIEVE_REG    6    /* wo */
  162.  
  163. /* Read this register to clear interrupt conditions */
  164. #define RESET_PARITY_INTERRUPT_REG    7    /* ro */
  165.  
  166. /* Write any value to this register to start an ini mode DMA recieve */
  167. #define START_DMA_INITIATOR_RECIEVE_REG 7    /* wo */
  168.  
  169. /* Note : PHASE_* macros are based on the values of the STATUS register */
  170. #define PHASE_MASK     (SR_MSG | SR_CD | SR_IO)
  171.  
  172. #define PHASE_DATAOUT    0
  173. #define PHASE_DATAIN    SR_IO
  174. #define PHASE_CMDOUT    SR_CD
  175. #define PHASE_STATIN    (SR_CD | SR_IO)
  176. #define PHASE_MSGOUT    (SR_MSG | SR_CD)
  177. #define PHASE_MSGIN    (SR_MSG | SR_CD | SR_IO)
  178. #define PHASE_UNKNOWN    0xff
  179.  
  180. /* 
  181.  * Convert status register phase to something we can use to set phase in 
  182.  * the target register so we can get phase mismatch interrupts on DMA 
  183.  * transfers.
  184.  */
  185.  
  186. #define PHASE_SR_TO_TCR(phase) ((phase) >> 2)    
  187.  
  188. /*
  189.  * The internal should_disconnect() function returns these based on the 
  190.  * expected length of a disconnect if a device supports disconnect/
  191.  * reconnect.
  192.  */
  193.  
  194. #define DISCONNECT_NONE        0
  195. #define DISCONNECT_TIME_TO_DATA    1
  196. #define DISCONNECT_LONG        2
  197.  
  198. /* 
  199.  * These are "special" values for the tag parameter passed to NCR5380_select.
  200.  */
  201.  
  202. #define TAG_NEXT    -1     /* Use next free tag */
  203. #define TAG_NONE    -2    /* 
  204.                  * Establish I_T_L nexus instead of I_T_L_Q
  205.                  * even on SCSI-II devices.
  206.                  */
  207.  
  208. /*
  209.  * These are "special" values for the irq and dma_channel fields of the 
  210.  * Scsi_Host structure
  211.  */
  212.  
  213. #define IRQ_NONE    255
  214. #define DMA_NONE    255
  215. #define IRQ_AUTO    254
  216. #define DMA_AUTO    254
  217.  
  218. #define FLAG_HAS_LAST_BYTE_SENT        1    /* NCR53c81 or better */
  219. #define FLAG_CHECK_LAST_BYTE_SENT    2    /* Only test once */
  220.  
  221. #ifndef ASM
  222. struct NCR5380_hostdata {
  223.     NCR5380_implementation_fields;        /* implmenentation specific */
  224.     unsigned char id_mask, id_higher_mask;    /* 1 << id, all bits greater */
  225.     volatile unsigned char busy[8];        /* index = target, bit = lun */
  226. #if defined(REAL_DMA) || defined(REAL_DMA_POLL)
  227.     volatile int dma_len;            /* requested length of DMA */
  228. #endif
  229.     volatile unsigned char last_message;    /* last message OUT */
  230.     volatile Scsi_Cmnd *connected;        /* currently connected command */
  231.     volatile Scsi_Cmnd *issue_queue;        /* waiting to be issued */
  232.     volatile Scsi_Cmnd *disconnected_queue;    /* waiting for reconnect */
  233.     int flags;
  234. #ifdef USLEEP
  235.     unsigned long time_expires;            /* in jiffies, set prior to sleeping */
  236.     struct Scsi_Host *next_timer;
  237. #endif
  238. };
  239.  
  240. #ifdef __KERNEL__
  241. static struct Scsi_Host *first_instance;        /* linked list of 5380's */
  242.  
  243. #if defined(AUTOPROBE_IRQ)
  244. static int NCR5380_probe_irq (struct Scsi_Host *instance, int possible);
  245. #endif
  246. static void NCR5380_init (struct Scsi_Host *instance);
  247. static void NCR5380_information_transfer (struct Scsi_Host *instance);
  248. static void NCR5380_intr (int irq);
  249. static void NCR5380_main (void);
  250. static void NCR5380_print_options (struct Scsi_Host *instance);
  251. #ifndef NCR5380_abort
  252. static
  253. #endif
  254. int NCR5380_abort (Scsi_Cmnd *cmd, int code);
  255. #ifndef NCR5380_reset
  256. static
  257. #endif
  258. int NCR5380_reset (Scsi_Cmnd *cmd);
  259. #ifndef NCR5380_queue_command
  260. static 
  261. #endif
  262. int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *));
  263.  
  264.  
  265. static void NCR5380_reselect (struct Scsi_Host *instance);
  266. static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag);
  267. #if defined(PSEUDO_DMA) || defined(REAL_DMA) || defined(REAL_DMA_POLL)
  268. static int NCR5380_transfer_dma (struct Scsi_Host *instance,
  269.         unsigned char *phase, int *count, unsigned char **data);
  270. #endif
  271. static int NCR5380_transfer_pio (struct Scsi_Host *instance,
  272.         unsigned char *phase, int *count, unsigned char **data);
  273.  
  274. #ifdef REAL_DMA
  275. static void NCR5380_dma_complete (struct Scsi_Host *instance);
  276. #endif
  277.  
  278.  
  279. #if (defined(REAL_DMA) || defined(REAL_DMA_POLL)) && defined(i386)
  280. static __inline__ int NCR5380_i386_dma_setup (struct Scsi_Host *instance,
  281.     unsigned char *ptr, unsigned int count, unsigned char mode) {
  282.     unsigned limit;
  283.  
  284.     if (instance->dma_channel <=3) {
  285.     if (count > 65536)
  286.         count = 65536;
  287.     limit = 65536 - (((unsigned) ptr) & 0xFFFF);
  288.     } else {
  289.     if (count > 65536 * 2) 
  290.         count = 65536 * 2;
  291.     limit = 65536* 2 - (((unsigned) ptr) & 0x1FFFF);
  292.     }
  293.  
  294.     if (count > limit) count = limit;
  295.  
  296.     if ((count & 1) || (((unsigned) ptr) & 1))
  297.     panic ("scsi%d : attmpted unaligned DMA transfer\n", instance->host_no);
  298.     cli();
  299.     disable_dma(instance->dma_channel);
  300.     clear_dma_ff(instance->dma_channel);
  301.     set_dma_addr(instance->dma_channel, (unsigned int) ptr);
  302.     set_dma_count(instance->dma_channel, count);
  303.     set_dma_mode(instance->dma_channel, mode);
  304.     enable_dma(instance->dma_channel);
  305.     sti();
  306.     return count;
  307. }
  308.  
  309. static __inline__ int NCR5380_i386_dma_write_setup (struct Scsi_Host *instance,
  310.     unsigned char *src, unsigned int count) {
  311.     return NCR5380_i386_dma_setup (instance, src, count, DMA_MODE_WRITE);
  312. }
  313.  
  314. static __inline__ int NCR5380_i386_dma_read_setup (struct Scsi_Host *instance,
  315.     unsigned char *src, unsigned int count) {
  316.     return NCR5380_i386_dma_setup (instance, src, count, DMA_MODE_READ);
  317. }
  318.  
  319. static __inline__ int NCR5380_i386_dma_residual (struct Scsi_Host *instance) {
  320.     register int tmp;
  321.     cli();
  322.     clear_dma_ff(instance->dma_channel);
  323.     tmp = get_dma_residue(instance->dma_channel);
  324.     sti();
  325.     return tmp;
  326. }
  327. #endif /* defined(REAL_DMA) && defined(i386)  */
  328. #endif __KERNEL_
  329. #endif /* ndef ASM */
  330. #endif /* NCR5380_H */
  331.